import os
import json

# 获取启动页图片链接
def get_launch_img():
    try:
        basedir=os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
        with open(basedir+'/appConfig.json','r') as config:
            data = json.loads(config.read()).get('launch')
            return data.get('imgUrl')
    except Exception as e:
        print('request launch_img error:',e)
        return None

# 保存启动页图片链接
def save_launch_img(new_img_url):
    try:
        condir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + '/appConfig.json'
        r = open(condir,'r')
        r_data = json.loads(r.read())
        r.close()
        launch = r_data.get('launch')

        new_img = {'imgUrl':new_img_url}
        launch.update(new_img)

        w_ = open(condir,'w')
        w_data = json.dumps(r_data,ensure_ascii = False)
        w_.write(w_data)
        w_.close()
    except Exception as e:
        print('save error:',e)
    finally:
        if r:
            r.close()
        if w_:
            w_.close()
